//定义登录成功后 所要保存的常量
const TokenKey = "accessToken"
const RefreshTokenKey = "refreshToken"
const CurrentUserKey = "currentUser"


//   设置保存token值和当前用户
export function setToken(token, refreshToken, currentUser) {

    // localStorage.setItem(key,value)：将value存储到key字段，并保存到本地储存中
    localStorage.setItem(TokenKey, token, );
    localStorage.setItem(RefreshTokenKey, refreshToken);
    localStorage.setItem(CurrentUserKey, currentUser);
}

//获取token
export function getToken() {
    return localStorage.getItem(TokenKey)
}

//获取refreshToken
export function getRefreshToken() {
    return localStorage.getItem(RefreshTokenKey)
}

//获取currentUser
export function getCurrentUser() {
    // localStorage.getItem(key):获取指定key本地存储的值
    return localStorage.getItem(CurrentUserKey)
}


//注销或退出登录时，清除token、refreshToken和currentUser
export function  clearToken() {
    localStorage.removeItem(TokenKey);
    localStorage.removeItem(RefreshTokenKey);
    localStorage.removeItem(CurrentUserKey);
}

//获取登录状态
export function isLogin() {
    let token = getToken();

    return token

}